﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//------------------------------------------------------
//クラス：H3A1 07
//名　前：仮屋　智央
//内　容：状況に応じたサウンドを再生するクラス
//　　　：
//------------------------------------------------------

namespace h3a1_felica2
{
    public class SoundUtils
    {
        private System.Media.SoundPlayer player = null;
        public void PlaySound(string str)
        {
            //再生されている時は停止させる
            if (player != null)
            {
                StopSound();
            }

            String uri;
            if (str == "ok")
            {
                uri = (System.Configuration.ConfigurationSettings.AppSettings["ok_sound"]);
            }
            else
            {
                uri = (System.Configuration.ConfigurationSettings.AppSettings["ng_sound"]);
            }

            // カレントディレクトリの取得
            string stCurrentDir = System.Environment.CurrentDirectory;
            string File = stCurrentDir + "\\" + uri;
            player = new System.Media.SoundPlayer(File);
            //非同期再生
            player.PlaySync();
        }
        private void StopSound()
        {
            if (player != null)
            {
                player.Stop();
                player.Dispose();
                player = null;
            }
        }
    }
}
